<!--
 * @Description: 掌大精英数据
 * @Author: liyujie
 * @Date: 2021/06/04
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/06/04
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    掌大精英数据
                </div>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">精英类型</p>
                    <el-select
                        v-model="filterData.is_trial_stuagent"
                        filterable
                        placeholder="全部"
                        size="medium"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in agentTypeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        学校名称
                    </p>
                    <el-cascader
                        placeholder="请选择"
                        :options="school_tree"
                        filterable
                        clearable
                        change-on-select
                        expand-trigger="click"
                        v-model="school"
                        size="medium"
                        :props="{
                            label: 'name',
                            value: 'id',
                            children: 'children'
                        }"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        用户编号
                    </p>
                    <el-input
                        placeholder="搜索用户编号"
                        v-model="filterData.keyword_student_id"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 240px"
                        @change="getTableData(1)"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        邀请码
                    </p>
                    <el-input
                        placeholder="搜索邀请码"
                        v-model="filterData.invite_code"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 240px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <!--v2.0.9新精英系统隐藏-->
                <!--<div class="header-new-box">
                    <p class="header-new-box-title">
                        考核结果
                    </p>
                    <el-select
                        v-model="filterData.appraisal"
                        filterable
                        placeholder="全部"
                        size="medium"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in appraisalList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>-->
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        是否班级认证
                    </p>
                    <el-select
                        v-model="filterData.class_verify"
                        filterable
                        placeholder="全部"
                        size="medium"
                        @change="getTableData(1)"
                    >
                        <el-option
                            label="全部"
                            :value="99"
                        />
                        <el-option
                            label="是"
                            :value="1"
                        />
                        <el-option
                            label="否"
                            :value="0"
                        />
                    </el-select>
                </div>
                <!-- <div class="header-new-box">
                    <p class="header-new-box-title">
                        代理类目
                    </p>
                    <el-select
                        v-model="filterData.goods_agent_cate_no"
                        clearable
                        filterable
                        placeholder="全部"
                        size="medium"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in cateList"
                            :key="item.cate_no"
                            :label="item.cate_name"
                            :value="item.cate_no"
                        />
                    </el-select>
                </div> -->
                <!-- <div class="header-new-box">
                    <p class="header-new-box-title">代理店铺</p>
                    <el-input
                        v-model="filterData.shop_keyword"
                        placeholder="请输入代理店铺名称"
                        suffix-icon="el-icon-search"
                        size="medium"
                        clearable
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div> -->
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        精英等级
                    </p>
                    <el-select
                        v-model="filterData.agent_level"
                        filterable
                        clearable
                        placeholder="全部"
                        size="medium"
                        @change="getTableData(1)"
                    >
                        <el-option
                            label="全部"
                            value=""
                        />
                        <el-option
                            v-for="item in 6"
                            :key="item"
                            :label="`E${item - 1}`"
                            :value="item - 1"
                        />

                    </el-select>
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                    <el-button
                        type="primary"
                        size="small"
                        @click="dialogVisibleAdd = true"
                    >
                        添加体验精英
                    </el-button>
                </div>
            </div>
            <!--筛选-->
            <!-- table -->
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                    ref="table"
                    :cell-style="{height: '105px'}"
                    class="data-table"
                    v-loading="tableLoading"
                    @sort-change="handleSortChanged"
                >
                    <el-table-column
                        label="序号"
                        align="center"
                        width="50"
                        type="index"
                        fixed="left"
                    />
                    <el-table-column
                        label="用户信息"
                        width="200"
                        fixed="left"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="cell-title">
                                <div class="user-name">{{ scope.row.true_name ? scope.row.true_name : '--' }}</div>
                                <div class="user-tags">
                                    <div class="tag-item">
                                        <img
                                            src="@/assets/image/finance/class-light.png"
                                            v-if="scope.row.class_verify"
                                        >
                                        <img
                                            src="@/assets/image/finance/class.png"
                                            v-else
                                        >
                                    </div>
                                </div>
                            </div>
                            <div class="cell-tips">手机号：{{ scope.row.phone }}</div>
                            <div class="cell-tips">用户ID：{{ scope.row.student_no }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="精英类型"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.is_trial_stuagent == 1 ? '体验精英' : '精英用户' }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="精英等级"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            E{{ scope.row.agent_level }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="invite_code"
                        label="邀请码"
                        align="center"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        label="学校名称"
                        prop="school_name"
                        show-overflow-tooltip
                        width="130"
                        :formatter="emptyFormatter"
                    />
                    <!--v2.0.9新精英系统隐藏-->
                    <!--<el-table-column
                        prop="agent_type"
                        label="精英类型"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <span v-if="scope.row.agent_type === 1">自由精英</span>
                            <span v-else-if="scope.row.agent_type === 2">专职精英</span>
                            <span v-else>&#45;&#45;</span>
                        </template>
                    </el-table-column>-->
                    <el-table-column
                        label="上级邀请码"
                        align="center"
                        :formatter="emptyFormatter"
                        :width="110"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.parent_stuagent.invite_code ? scope.row.parent_stuagent.invite_code : '--' }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="fans_buy_num"
                        label="0元购粉丝数"
                        align="center"
                        show-overflow-tooltip
                        :width="150"
                        sortable="custom"
                    />
                    <el-table-column
                        prop="fans_num"
                        label="直属粉丝"
                        align="center"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                        sortable="custom"
                        :width="100"
                    >
                        <template slot-scope="scope">
                            <el-popover
                                placement="bottom"
                                width="212"
                                trigger="hover"
                                popper-class="student-data-fans-view"
                            >
                                <div class="student-data-fans-view-item">
                                    直属校园精英粉丝：<span class="value">{{ scope.row.fans_agent_num }}人</span>
                                </div>
                                <div class="student-data-fans-view-item">
                                    直属普通用户粉丝：<span class="value">{{ scope.row.fans_general_num }}人</span>
                                </div>
                                <el-button
                                    slot="reference"
                                    type="text"
                                    @click="handleRoute('studentPeiFans', { phone: scope.row.phone, true_name: scope.row.true_name, agent_no: scope.row.agent_no})"
                                >
                                    {{ scope.row.fans_num }}人(查看)
                                </el-button>
                            </el-popover>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="buy_num"
                        label="独立购买人数"
                        align="center"
                        :width="130"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                        sortable="custom"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="handleRoute('studentPeiFans', { phone: scope.row.phone, true_name: scope.row.true_name, agent_no: scope.row.agent_no, purchase: 1})"
                            >
                                {{ scope.row.buy_num }}人
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="grand_fans_num"
                        label="二级粉丝"
                        :width="100"
                        align="center"
                        show-overflow-tooltip
                        sortable="custom"
                    />
                    <!-- <el-table-column
                        prop="agent_shop_num"
                        label="代理店铺"
                        align="center"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                        :width="100"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                v-if="Number(scope.row.agent_shop_num) > 0"
                                @click="fnCheckAgent(scope.row)"
                            >
                                {{ scope.row.agent_shop_num }}个
                            </el-button>
                            <span v-else>
                                --
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="goods_agent_cate_name"
                        label="代理类目"
                        align="center"
                        width="130"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                    /> -->
                    <el-table-column
                        prop="order_num"
                        label="总订单数"
                        align="center"
                        :width="100"
                        show-overflow-tooltip
                        sortable="custom"
                    />
                    <el-table-column
                        prop="self_order_num"
                        label="自营订单数"
                        align="center"
                        :width="120"
                        show-overflow-tooltip
                        sortable="custom"
                    />
                    <el-table-column
                        prop="consume_money"
                        label="有效消费金额"
                        :width="130"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                        align="center"
                        sortable="custom"
                    >
                        <template slot-scope="scope">
                            <span>{{ scope.row.consume_money | setMoney }}元</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="rebate_money"
                        label="所得分佣"
                        :width="120"
                        align="center"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                        sortable="custom"
                    >
                        <template slot-scope="scope">
                            <span>{{ scope.row.rebate_money | setMoney }}元</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="total_income"
                        label="所有收入总计"
                        :width="140"
                        align="center"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                v-if="scope.row.total_income"
                                @click="handleRoute('studentDataMoney', {agent_no: scope.row.agent_no, true_name: scope.row.true_name, phone: scope.row.phone})"
                            >
                                {{ scope.row.total_income | setMoney }}元
                            </el-button>
                            <div v-else>--</div>
                        </template>
                    </el-table-column>
                    <!--v2.0.9新精英系统隐藏-->
                    <!--<el-table-column
                        label="考核结果"
                        align="center"
                        width="130"
                    >
                        <template slot-scope="scope">
                            <div class="status-wrapper">
                                <div
                                    :class="['status-dot', scope.row.appraisal === 1 ? 'success' : 'danger']"
                                    v-if="scope.row.appraisal"
                                />
                                <div>{{ scope.row.appraisal | setAppraisa }}</div>
                            </div>
                        </template>
                    </el-table-column>-->
                    <el-table-column
                        label="操作"
                        align="left"
                        width="160"
                        fixed="right"
                    >
                        <template slot-scope="scope">
                            <div class="option-btn-group">
                                <el-button
                                    type="text"
                                    @click="fnUpgrade(scope.row, 1)"
                                >
                                    升级
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="fnUpgrade(scope.row, 2)"
                                >
                                    降级
                                </el-button>
                                <el-button
                                    type="text"
                                    @click="fnUnBind(scope.row)"
                                    :disabled="scope.row.is_trial_stuagent && scope.row.parent_stuagent.invite_code ? false : true"
                                >
                                    解绑
                                </el-button>
                                <!--v2.0.9新精英系统隐藏-->
                                <!--<el-button
                                    type="text"
                                    style="color: #F95B56"
                                    @click="fnUpgrade(scope.row, 3)"
                                >
                                    淘汰
                                </el-button>-->
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- /table -->
            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>

        <!-- 代理店铺 -->
        <el-dialog
            :visible.sync="dialogAgentShop"
            :close-on-click-modal="false"
            width="500px"
            title="代理店铺"
        >
            <el-table
                :data="agentShopList"
                style="width: 100%"
            >
                <!-- 测试字段 -->
                <el-table-column
                    prop="shop_title"
                    align="center"
                    label="店铺名称"
                />
                <el-table-column
                    prop="verify_time"
                    align="center"
                    label="代理时间"
                >
                    <template slot-scope="scope">
                        {{ scope.row.verify_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                    </template>
                </el-table-column>
            </el-table>
            <div class="zd-dialog-foot">
                <el-button
                    size="medium"
                    type="primary"
                    style="width: 120px"
                    @click="dialogAgentShop = false"
                >
                    确定
                </el-button>
            </div>
        </el-dialog>

        <!-- 淘汰弹窗 -->
        <el-dialog
            :visible.sync="dialogTao"
            :close-on-click-modal="false"
            width="622px"
            title="淘汰该用户"
            @close="tao_text = ''"
        >
            <p class="zd-tips">一旦淘汰，将会取消该用户精英的身份，且不可取消，请非常谨慎的操作！</p>
            <div class="zd-content">
                <el-input
                    type="textarea"
                    :autosize="{ minRows: 4, maxRows: 6}"
                    placeholder="请填写淘汰理由"
                    v-model="tao_text"
                />
            </div>
            <div
                class="zd-foot"
                style="margin-bottom:0"
            >
                <el-button
                    size="medium"
                    @click=" dialogTao = false "
                    style="width:120px"
                >
                    取消
                </el-button>
                <el-button
                    type="primary"
                    size="medium"
                    style="margin-left: 40px;width:120px"
                    @click="fnConfirmtao()"
                    :disabled="!tao_text"
                >
                    确定
                </el-button>
            </div>
        </el-dialog>

        <!-- 新增管培生 -->
        <el-dialog
            title="新增掌大精英"
            :visible.sync="dialogVisibleAdd"
            width="622px"
            class="el-dialogAdd"
        >
            <el-form
                :model="ruleForm"
                class="demo-ruleForm"
                @submit.native.prevent
            >
                <el-form-item
                    label="搜索掌大精英手机号或唯一ID:"
                    label-width="200px"
                >
                    <div class="__flex">
                        <el-input
                            v-model="ruleForm.tel"
                            size="small"
                            clearable
                            placeholder="手机号或用户ID"
                            class="search-ipt"
                            maxlength="11"
                            show-word-limit
                            :style="{width: '350px'}"
                            @keyup.native.enter="fnGetUserTel()"
                        />
                        <el-button
                            size="small"
                            type="primary"
                            :style="{marginLeft: '20px'}"
                            @click="fnGetUserTel()"
                        >
                            搜索
                        </el-button>
                    </div>
                </el-form-item>
                <el-tag
                    v-for="(tag,index) in dynamicTags"
                    :key="index"
                    closable
                    :disable-transitions="false"
                    @close="handleClose(tag)"
                    :style="{marginLeft: '24px'}"
                >
                    {{ tag.true_name }}-{{ tag.school_name }}--{{ tag.phone }}
                </el-tag>
            </el-form>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    type="primary"
                    size="small"
                    @click="fnSubmitAdd()"
                    :style="{width: '120px'}"
                >
                    确 定
                </el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import RejectDialog from "@/components/dialog/reject-dialog";

export default {
    name: 'StudentData',
    mixins: [back],
    components: {RejectDialog},
    data() {
        return {
            filterData: {
                // 学生编号
                keyword_student_id: '',
                province_id: '',
                city_id: '',
                school_id: '',
                // 代理等级
                agent_level: '',
                // 邀请码
                invite_code: '',
                // 考核结果
                appraisal: 99,
                // 代理类目编号
                // goods_agent_cate_no: '',
                // 代理店铺
                // shop_keyword: '',
                sort_field: '',
                sort_type: '',
                class_verify: 99,
                // 2.1.0新增
                is_trial_stuagent: 99
            },
            school: [],
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            // 结果列表
            appraisalList: [
                {value: 99, label: '全部'},
                {value: 0, label: '未判断'},
                {value: 1, label: '合格'},
                {value: -1, label: '不合格'}
            ],
            agentTypeList: [
                {value: 99, label: '全部'},
                {value: 1, label: '体验精英'},
                {value: 0, label: '精英用户'}
            ],
            // 学校列表
            school_tree: [],
            // 代理商品类目列表
            cateList: [],
            agent_no: '',
            tao_text: '',
            dialogTao: false,
            dialogAgentShop: false,
            agentShopList: [],
            authResult: {},
            // 新增体验精英相关参数
            dialogVisibleAdd: false,
            ruleForm: {
                tel: ''
            },
            dynamicTags: []
        };
    },
    computed: {},
    watch: {
        school(value) {
            this.filterData.province_id = value ? value[0] : '';
            this.filterData.city_id = value ? value[1] : '';
            this.filterData.school_id = value ? value[2] : '';
            this.getTableData(1);
        }
    },
    filters: {
        setMoney (val) {
            if (val === null) {
                return '0.00';
            }
            return Number(val).toFixed(2);
        },
        setAppraisa (val) {
            if (val === 1) {
                return '合格';
            } else if (val === -1) {
                return '不合格';
            } else if (val === 0) {
                return '--';
            }
        }
    },
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '掌大精英'}, {title: '掌大精英数据'}]);
        this.authResult = this.$route.meta.authResult;
        this.getParam();
        this.getTableData();
        this.getSchoolTree();
        this.getCateList();
    },

    methods: {

        /**
         * 获取url参数
         */
        getParam () {
            let query = this.$route.query;

            if (query.phone !== undefined || query.page !== undefined || query.header !== undefined ) {
                this.filterData.tel = query.phone;
            }
            if(query.student_no) {
                this.filterData.keyword_student_id = query.student_no;
            }
            if(query.cate_no) {
                // this.filterData.goods_agent_cate_no = query.cate_no;
            }
            if(query.shop_title) {
                // this.filterData.shop_keyword = query.shop_title;
            }
        },

        /**
         * 获取代理类目商品列表
         */
        getCateList () {
            this.$post('/student/stuagent_rebate%5Cget_goods_agent_cate_simple_list', {},resp=>{
                if (resp.code === 1) {
                    this.cateList = resp.data.list;
                } else {
                    this.$notify({
                        type: 'waring',
                        title: '提示',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * @description 获取省/市/学校三级联动
         */
        getSchoolTree () {
            this.$post('/student/local_info%5Cschool_tree',{},resp => {
                if (resp.code === 1) {
                    this.school_tree = resp.data.tree;
                }
            });
        },

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/stuagent_rebate%5Cget_rebate_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 打开弹窗
         */
        fnUpgrade (row, status) {
            this.agent_no = row.agent_no;
            this.agent_level = row.agent_level;

            if(status === 1) {
                if(Number(this.agent_level) >= 5) {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: '抱歉,已经是最高等级了'
                    });
                    return;
                }
                this.setUpGrand(row);
            } else if (status === 2) {
                if(Number(this.agent_level) === 0) {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: '抱歉,已经是最低等级了'
                    });
                    return;
                }
                this.setDownGrand(row);
            } else if (status === 3) {
                if(this.authResult.auth_tao) {
                    this.dialogTao = true;
                } else {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: '抱歉,你还没有权限'
                    });
                }
            }
        },

        /**
         * 降级
         */
        setDownGrand(row) {
            this.$confirm('降级最低只能降到该用户本来的等级，是否确认降级？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/stuagent_rebate%5Cdegrade_level',{
                    agent_no: row.agent_no
                },resp=> {
                    if (resp.code === 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            type: 'success',
                            message: `已将该精英降级至E${Number(row.agent_level - 1)}`
                        });
                    } else {
                        this.$notify({
                            title: '提示',
                            type: 'success',
                            message: resp.msg
                        });
                    }
                });
            });
        },

        /**
         * 升级
         */
        setUpGrand(row) {
            this.$confirm('一旦确认，将用户等级将会立即升级，请谨慎操作，是否确认升级？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/stuagent_rebate%5Cupgrade_level',{
                    agent_no: row.agent_no
                },resp=> {
                    if (resp.code === 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            type: 'success',
                            message: `已将该精英升级至E${Number(row.agent_level + 1)}`
                        });
                    } else {
                        this.$notify({
                            title: '提示',
                            type: 'success',
                            message: resp.msg
                        });
                    }
                });
            });
        },

        /**
         * 淘汰
         */
        fnConfirmtao (row) {
            this.$post('/student/stuagent_rebate%5Crevoke_agent',{
                agent_no: this.agent_no,
                reason: this.tao_text
            },resp=> {
                if (resp.code === 1) {
                    this.dialogTao = false;
                    this.$notify({
                        title: '提示',
                        type: 'success',
                        message: '已取消该用户的精英身份'
                    });
                    this.getTableData(1);
                } else {
                    this.$notify({
                        title: '提示',
                        type: 'success',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 查看代理店铺
         */
        fnCheckAgent (row) {
            this.$post('/student/shop_agent_shop_student%5Cget_agent_shop_list',{
                agent_no: row.agent_no
            },resp=> {
                if (resp.code === 1) {
                    this.agentShopList = resp.data.list;
                    this.dialogAgentShop = !this.dialogAgentShop;
                } else {
                    this.$notify({
                        title: '提示',
                        type: 'success',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 数据排序
         */
        handleSortChanged(data) {
            console.log(data, 'data');
            let sortTypeMap = {
                ascending: 0,
                descending: 1
            };

            // 0:加入时间,1:0元购人数,2:下属粉丝数,3:二级粉丝数,4:独立购买人数,5:总订单数,6:自营订单数,7:有效消费金额数,8:所得分佣金额,9:代理等级
            let sortFieldMap = {
                "fans_buy_num": 1,
                "fans_num": 2,
                "grand_fans_num": 3,
                "buy_num": 4,
                "order_num": 5,
                "self_order_num": 6,
                "consume_money": 7,
                "rebate_money": 8,
                "agent_level": 9
            };

            if (data.order) {
                this.filterData.sort_field = sortFieldMap[data.prop];
                this.filterData.sort_type = sortTypeMap[data.order];
            } else {
                this.filterData.sort_field = '';
                this.filterData.sort_type = '';
            }

            this.getTableData();
        },

        /**
         * @description 搜索用户
         */
        fnGetUserTel () {
            let arr = [];

            console.log('this.ruleForm.tel', this.ruleForm.tel);
            if(!this.ruleForm.tel) {
                this.$message({
                    type: 'waring',
                    message: '手机号码不可以为空'
                });
                return false;
            }

            if(this.ruleForm.tel.length < 11) {
                this.$message({
                    type: 'waring',
                    message: '请输入正确的手机号码'
                });
                return false;
            }

            this.$post('/student/stuagent%5Cget_by_phone',{
                phone: this.ruleForm.tel
            },resp=>{
                if (resp.code == 1 && resp.data.phone !== null) {
                    arr.push(resp.data);
                    this.dynamicTags = this.dynamicTags.concat(arr);
                    this.ruleForm.tel = '';
                }else if (resp.code == 1 && resp.data.phone === null) {
                    this.$message({
                        type: 'waring',
                        message: '手机号错误,查无此人'
                    });
                    this.ruleForm.tel = '';
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'waring',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * @description 移除手机号
         */
        handleClose (tag) {
            this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
        },

        /**
         * @description 确认新增体验精英
         */
        fnSubmitAdd () {
            if (this.dynamicTags.length == 0) {
                this.$message({
                    type: 'waring',
                    message: '新增数据不可以为空'
                });
            } else {
                console.log('dynamicTags', this.dynamicTags);

                if(!this.dynamicTags.length) return false;

                for(let i=0; i<this.dynamicTags.length;i++){
                    const agent_no = this.dynamicTags[i]['agent_no'];

                    this.$post('/student/stuagent%5Cset_trial_stuagent',{
                        agent_no: agent_no,
                        is_trial_stuagent: 1
                    },resp=> {
                        if (resp.code === 1) {
                            //
                        }
                    });
                }

                this.dialogVisibleAdd = false;

                setTimeout(() => {
                    this.$notify({
                        title: '提示',
                        type: 'success',
                        message: '设置成功'
                    });
                    this.getTableData();
                }, 800);
            }
        },

        /**
         * @description 解绑
         */
        fnUnBind (row) {
            this.$confirm('确定解除与上级的关系?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/stuagent%5Cdelete_fans',{
                    student_no: row.student_no
                },resp=> {
                    if (resp.code === 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            type: 'success',
                            message: '解除成功'
                        });
                    } else {
                        this.$notify({
                            title: '提示',
                            type: 'success',
                            message: resp.msg
                        });
                    }
                });
            });
        }
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 0 24px;
            margin-top: 12px;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }
        }

        // 表格
        .table-wrapper {
            padding: 0 24px;
            flex: 1;
            height: 0;
            .cell-title {
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                margin-bottom: 12px;
                display: flex;
                align-items: center;
                .user-name {
                    max-width: 124px;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                }
                .user-tags {
                    display: flex;
                    align-items: center;
                    margin-left: 6px;
                    .tag-item {
                        margin-right: 4px;
                        display: flex;
                        align-items: center;
                        img {
                            height: 14px;
                        }
                    }
                }
            }
            .cell-content {
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 3;
            }
            .cell-tips {
                color: #999;
            }
        }

        .status-wrapper {
            display: flex;
            align-items: center;
            justify-content: center;

            .status-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin-right: 5px;

                &.success {
                    background: #4CD964;
                }

                &.danger {
                    background: #FF3030;
                }

                &.warning {
                    background: #FFA72D;
                }

                &.normal {
                    background: #A6A6A6;
                }
            }
        }

        /* 分页 */

        .pagination-wrapper {
            padding: 12px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }
    .data-table {
        ::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }
        // 操作按钮
        .option-btn-group {
            .el-button {
                margin-left: 0;
                margin-right: 10px;
            }
        }
    }
    .zd-tips {
        color: #F8A127;
        font-size: 14px;
        margin-bottom: 24px;
    }
    .zd-content {
        display: flex;
        .zd-content-title {
            color: #000;
            font-size: 14px;
            white-space: nowrap;
            margin-right: 6px;
        }
    }
    .zd-foot {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 30px;
        margin-bottom: 25px;
    }
    .zd-dialog-foot {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 20px;
    }
}
.__flex {
    display: flex;
    align-items: center;
}
</style>

<style lang="less">
.student-data-fans-view {
    padding: 12px 24px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
    &-item {
        margin: 8px 0;
        .value {
            color: #F79038;
        }
    }
    .el-dialogAdd {
        /deep/ .el-dialog__body {
            padding: 24px 32px;
        }
    }
}
</style>
